package com.codeest.geeknews.ui.main.activity;

import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.TextView;

import com.codeest.geeknews.R;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Created by admin on 2017/7/5.
 */
@RunWith(AndroidJUnit4.class)
public class WelcomeActivityTest extends ActivityInstrumentationTestCase2<WelcomeActivity> {
    private WelcomeActivity mActivity;
    private TextView mTextView;

    public WelcomeActivityTest() {
        super(WelcomeActivity.class);
    }

    @Before
    public void setUp() throws Exception {
        super.setUp();
        // @Before注解表示在执行所有的testCase之前要做的事情
        injectInstrumentation(InstrumentationRegistry.getInstrumentation());
        // getActivity()方法会在开始所有的testCase之前启动相应的Activity
        mActivity = getActivity();
        // findViewById()很熟悉吧？找到我要测试的控件
        mTextView = (TextView) mActivity.findViewById(R.id.tv_welcome_author);
    }

    @Test
    public void testPreconditions() {
        // @Test注解表示一个测试用例方法
        assertNotNull("AppStartActivity is null", mActivity);
    }

    @Test
    public void testContentDisplayed() {
        // 这里就是我们测试的目标，判断目标控件的text不为空
        String content = mTextView.getText().toString();
        assertNotNull("AppStartActivity Content is Null", content);
    }
}
